<template>
    <div>
        <!-- 面包屑导航 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>订单管理</el-breadcrumb-item>
            <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-row>
                <el-col :span="6">
                    <el-input
                        placeholder="请输入内容"
                        v-model="queryinfo.query"
                        clearable
                        @clear="getOrderList"
                    >
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <!-- 展示用户信息区域 -->
            <el-table :data="orderList" border stripe>
                <el-table-column type="index" label="#"></el-table-column>
                <el-table-column prop="order_number" label="订单编号"></el-table-column>
                <el-table-column prop="order_price" label="订单价格"></el-table-column>
                <el-table-column prop="order_pay" label="是否付款">
                    <template slot-scope="scope">
                        <div>
                            <el-tag v-if="scope.row.order_pay==='1'">已付款</el-tag>
                            <el-tag v-else type="danger">未付款</el-tag>
                        </div>
                    </template>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货"></el-table-column>
                <el-table-column prop="create_time" label="下单时间">
                    <template slot-scope="scope">
                        <div>{{scope.row.create_time|dateFormat}}</div>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <div>
                            <!-- 修改地址 -->
                            <el-button
                                type="primary"
                                icon="el-icon-edit"
                                size="mini"
                                @click="showEditOrder"
                            ></el-button>
                            <!-- 查看物流 -->
                            <el-button
                                type="danger"
                                icon="el-icon-delete"
                                size="mini"
                                @click="showOrder"
                            ></el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页页码条区域 -->
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="queryinfo.pagenum"
                :page-sizes="[5, 10, 15, 20]"
                :page-size="queryinfo.pagesize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
            ></el-pagination>
        </el-card>
        <!-- 修改收货地址 -->
        <el-dialog
            title="修改收货地址"
            :visible.sync="addressVisible"
            width="50%"
            @close="addressDialogClosed"
        >
            <!-- 添加表单 -->
            <el-form
                :model="addressForm"
                :rules="addressFormRules"
                ref="addressFormRef"
                label-width="100px"
            >
                <el-form-item label="省市区县" prop="address1">
                    <el-cascader :options="cityData" v-model="addressForm.address1"></el-cascader>
                </el-form-item>
                <el-form-item label="详细地址" prop="address2">
                    <el-input v-model="addressForm.address2"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addressVisible = false">取 消</el-button>
                <el-button type="primary" @click="addressVisible = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
// 引入省市联动文件
import cityData from './citydata.js'
export default {
    data() {
        return {
            queryinfo: {
                query: '',
                pagenum: 1,
                pagesize: 10
            },
            total: 0,
            orderList: [],
            addressVisible: false,
            addressForm: {
                address1: [],
                address2: ''
            },
            addressFormRules: {
                address1: [
                    {
                        required: true,
                        message: '请选择省市区县',
                        trigger: 'blur'
                    }
                ],
                address2: [
                    {
                        required: true,
                        message: '请输入详细地址',
                        trigger: 'blur'
                    }
                ]
            },
            cityData: cityData
        }
    },
    created() {
        this.getOrderList()
    },
    methods: {
        async getOrderList() {
            const { data: res } = await this.$http.get('orders', {
                params: this.queryinfo
            })
            if (res.meta.status !== 200) {
                return this.$message.error('获取订单列表失败')
            }
            this.orderList = res.data.goods
            this.total = res.data.total
        },
        handleSizeChange(val) {
            this.queryinfo.pagesize = val
            this.getOrderList()
        },
        handleCurrentChange(val) {
            this.queryinfo.pagenum = val
            this.getOrderList()
        },
        showEditOrder() {
           this.$message.info('时间关系暂没完成')
        },
        showOrder() {
           this.$message.info('时间关系暂没完成')
        },
        addressDialogClosed(){}
    }
}
</script>

<style lang='less' scoped>
</style>